import os

BASE_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))),'apiSpider')
DATA_BASE = os.path.join(BASE_DIR, 'data')

# 指定爬虫
SPIDERNAME = 'Spiders.get_month_average_info_by_city'
# 指定存储模块
DATASAVENAME = 'DataSave.write_csv'
# 指定 csv文件名
CSV_PATH = os.path.join(DATA_BASE, 'mydata.csv')

num_of_threads = 10

# 是否使用代理
useProxy = False

data_url = 'https://www.aqistudy.cn/historydata/api/historyapi.php'
city_url = 'https://www.aqistudy.cn/historydata/'
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p"


DB = {
    'host': '47.107.173.225',
    'port': 3306,
    'user': 'root',
    'passwd': 'root',
    'db': 'openApiStudy',
}

BASE_LOG_DIR = os.path.join(BASE_DIR, 'log')
LOGGING = {
    'formatters': {
        'standard': {
            'format': '[%(asctime)s][%(threadName)s:%(thread)d][task_id:%(name)s][%(filename)s:%(lineno)d]'
                      '[%(levelname)s][%(message)s]'
        },
        'simple': {
            'format': '[%(levelname)s][%(asctime)s][%(filename)s:%(lineno)d]%(message)s'
        },
        'collect': {
            'format': '%(message)s'
        },

    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'default': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_LOG_DIR, 'info.log'),
            'formatter': 'standard',
            'encoding': 'utf-8',
        },
        'error': {
            'level': 'ERROR',
            'class': 'logging.FileHandler',
            'filename': os.path.join(BASE_LOG_DIR, 'error.log'),
            'formatter': 'standard',
            'encoding': 'utf-8',
        },
    },
    'logger': {
        'handlers': ['console', 'error'],
        'level': 'DEBUG',
        'propagate': True,
    },
}